unit XPSP4SetupMainFormUnit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, helper;

type
  TXPSP4SetupMainForm = class(TForm)
    ProgressBar1: TProgressBar;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    function ProcessReceivedData(s: String): Integer;
    procedure WMCopyData(var Msg: TWMCopyData);message WM_COPYDATA;
  end;

var
  XPSP4SetupMainForm: TXPSP4SetupMainForm;

implementation

{$R *.dfm}

procedure TXPSP4SetupMainForm.FormActivate(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;

procedure DisplayMessage(text:String;title:String);
begin
MessageBox(XPSP4SetupMainForm.Handle, PChar(text), PChar(title), MB_ICONEXCLAMATION);
end;
function TXPSP4SetupMainForm.ProcessReceivedData(s: String): Integer;
begin
if s = 'installingchrome' then
begin
  ProgressBar1.Position := 10;
  Label1.Caption := GetText('installingchrome');
end
else if s = 'installingsandboxie' then
begin
  ProgressBar1.Position := 60;
  Label1.Caption := GetText('installingsandboxie');
end
else if s = 'installingsopen' then
begin
  ProgressBar1.Position := 90;
  Label1.Caption := GetText('installingsopen');
end
else if s = 'done' then
begin
  ProgressBar1.Position := 100;
  Label1.Caption := GetText('done');
  DisplayMessage(GetText('donemessage'),GetText('done'));
  Application.Terminate;
end
else if s = 'blahblah' then
begin
  ;
end;
end;
procedure TXPSP4SetupMainForm.WMCopyData(var Msg: TWMCopyData);
var
  s: string;
begin
  s := PChar(Msg.copyDataStruct.lpData);
  //ShowMessage('s="' + s + '"');
  Msg.Result := ProcessReceivedData(s);
  // Send something back
  // msg.Result := 2006;
end;

function Setup_Thread(Parameter : Pointer) : Integer;
var
SetupExePath:String;
SandboxieCommand:String;
begin
SetupExePath := ExtractFilePath(Application.ExeName);
WmCopyData_SendString(XPSP4SetupMainForm.Handle,'installingchrome');
//DisplayMessage(SetupExePath+GetText('chromefile'),'chrome');
ExecAndWait(SetupExePath+GetText('chromefile'),'');
WmCopyData_SendString(XPSP4SetupMainForm.Handle,'installingsandboxie');
SandboxieCommand := '"'+SetupExePath+'sandboxie\SandboxieInstall.exe" '+
                    GetText('sandboxiecommand')+GetProgramFilesDir+'Sandboxie';
//DisplayMessage(SandboxieCommand,'sandboxie');
ExecAndWait(SetupExePath+'sandboxie\SandboxieInstall.exe',SandboxieCommand);
WmCopyData_SendString(XPSP4SetupMainForm.Handle,'installingsopen');
ExecAndWait(SetupExePath+'sopen\sopen.exe',
            '"'+SetupExePath+'sopen\sopen.exe" setup');
WmCopyData_SendString(XPSP4SetupMainForm.Handle,'done');
EndThread(0);
end;

procedure TXPSP4SetupMainForm.FormCreate(Sender: TObject);
var
id1: LongWord;
thread1: Integer;
begin
LocaleId := '';
ProgressBar1.Position := 0;

Width := 400;

ProgressBar1.Top := 5;
ProgressBar1.Left := 5;
ProgressBar1.Width := ClientWidth - 5*2;
Label1.Top := ProgressBar1.Top + ProgressBar1.Height + 5;
Label1.Left := 5;
ClientHeight := Label1.Top + Label1.Height + 5;

Left := (Screen.Width - Width) div 2;
Top := (Screen.Height - Height) div 2;

thread1 := BeginThread(nil,0,Addr(Setup_Thread),nil,0,id1);
end;

procedure TXPSP4SetupMainForm.FormShow(Sender: TObject);
begin
ShowWindow(Application.Handle, SW_HIDE);
end;

end.
